import { rejects } from "assert"

import store from '../store/index'

const BaseUrl = "https://api.imooc-blog.lgdsunday.club/api"

function request ({url,data,method}){
    return new Promise((resolve,reject)=>{
        uni.request({
            url: BaseUrl+url,
            header: {
                icode: '51AB1BCE7DE3E3A0',
                Authorization:store.state.user.token
                },
            data,
            method,
            success: ({data,statusCode,header})=>{
                if(data.success){
                    resolve(data)
                }else{
                    uni.showToast({
                        title: data.message,
                        icon: 'success',
                        mask: true,
                        duration:3000
                    })
                }
                reject(data.message)
            },
            fail: (err)=>{
                reject(err)
            },
            complete: ()=>{
               uni.hideLoading()
            }
        });
})
}

export default request